package com.dream.model.app;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Type;

import com.dream.model.base.AppModelBase;
import com.google.common.collect.Lists;

@Entity
@Table(name="t_app_org")
public class AppOrg extends AppModelBase implements Serializable , Comparable<AppOrg>  {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2059115517153477321L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name="name")
	private String name;
	
	@Column(name="parent_id")
	private Long parentId;
	
	@Column(name="level")
	private Integer level;
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private Boolean deleted = false;
	
	@Transient
	private List<AppOrg> children = Lists.newArrayList();
	
	@Transient
	private Boolean checked =false;
	
	@Transient
	private Boolean open =true;
	
	public Boolean getChecked() {
		return checked;
	}

	public void setChecked(Boolean checked) {
		this.checked = checked;
	}

	public Boolean getOpen() {
		return open;
	}

	public void setOpen(Boolean open) {
		this.open = open;
	}

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}
	
	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	public Boolean getDeleted() {
		return deleted;
	}

	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}

	public List<AppOrg> getChildren() {
		return children;
	}

	public void setChildren(List<AppOrg> children) {
		this.children = children;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AppOrg other = (AppOrg) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public int compareTo(AppOrg o) {
		return o.getLevel().compareTo(this.getLevel());
	}
	
	
}
